package week_four;

public class Search2DMatrix_74 {
    public boolean searchMatrix(int[][] matrix, int target) {
        /*标准的二分查找，注意二位数组到一维数组下标的转换，下标/n=行，下标%n=列
         * */
        int m = matrix.length, n = matrix[0].length;
        int l = 0, r = m * n - 1;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (matrix[mid / n][mid % n] == target)
                return true;
            else if (matrix[mid / n][mid % n] < target) {
                l = mid + 1;
            } else
                r = mid - 1;
        }
        return false;
    }
}
